package com.xdxc.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xdxc.feign.QuestionFeign;
import com.xdxc.model.dto.CorrectAnswerDTO;
import com.xdxc.model.entity.Paper;
import com.xdxc.response.Result;

import com.xdxc.service.PaperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/correctAnswer")
@Slf4j
public class CorrectAnswerController {


    @Autowired
    private QuestionFeign questionFeign;

    @Autowired
    private PaperService paperService;

    @PostMapping("/getCorrectAnswer")
    public Result<CorrectAnswerDTO> getCorrectAnswer(@RequestParam long  paperId, @RequestParam long questionId , @RequestHeader HttpHeaders headers){
        log.info("Received headers: {}", headers);

        Paper paperQuestion = paperService.getOne(new LambdaQueryWrapper<Paper>().eq(Paper::getId,paperId));
        Result<CorrectAnswerDTO>  correctAnswerDTO   = questionFeign.getCorrectAnswer(questionId);
        correctAnswerDTO.getData().setScore( paperQuestion.getScore());
        return correctAnswerDTO;
    }
}
